import sys



class RedirectOutput:
    def __init__(self, output_Stream):
        self.output_Stream, sys.stdout = sys.stdout, output_Stream
    def __enter__(self):
        return self
    def __exit__(self, exc_type, exc_val, exc_tb):
        self.close()
    def close(self):
        sys.stdout = self.output_Stream

